package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.UserAuthenticationInfo;
import com.juyu.miliao.api.domain.dto.UserAuthenticationDTO;
import com.juyu.miliao.common.dataSource.tool.distributeOperate.DistributeOperate;
import com.juyu.miliao.common.dataSource.tool.operate.Operate;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author xuanqicheng
 * @create 2019-17-10:33
 */
@Repository
public class UserAuthenticationInfoDao {

    @Autowired
    private SqlSession sqlSession;

    @Operate("strategy('byUserId', #userId)")
    public UserAuthenticationInfo checkUserAutenticationByUserId(long userId) {
        return sqlSession.selectOne("checkUserAutenticationByUserId",userId);
    }

    @Operate("strategy('byUserId', #entity.userId)")
    public UserAuthenticationInfo selectInfoByUserIdAndPhone(UserAuthenticationInfo entity) {
        return sqlSession.selectOne("selectInfoByUserIdAndPhone",entity);
    }

    @Operate("strategy('byUserId', #entity.userId)")
    public void bindingPhone(UserAuthenticationInfo entity) {

        sqlSession.insert("bindingPhone",entity);

    }

    @Operate("strategy('byUserId', #userId)")
    public UserAuthenticationInfo getUserAuthenticationByUserId(Long userId) {
        return sqlSession.selectOne("getUserAuthenticationByUserId",userId);
    }

    @Operate("strategy('byUserId', #entity.userId)")
    public void bindingUser(UserAuthenticationInfo entity) {
        sqlSession.update("bindingUser",entity);
    }

    @DistributeOperate(ds = "miliao-user")
    public List<String> selectUserAuthenticationByPhone(String phone) {
        return sqlSession.selectList("selectUserAuthenticationByPhone",phone);
    }


    @Operate("strategy('byUserId', #userId)")
    public UserAuthenticationInfo getBindingPhoneByUserId(Long userId) {
        return sqlSession.selectOne("getBindingPhoneByUserId",userId);
    }

    @DistributeOperate(ds = "miliao-user")
    public List<Long> selectUserIdByPhone(String phone) {
        return sqlSession.selectList("selectUserAuthenticationOnUserIdByPhone",phone);
    }

    @Operate("strategy('byUserId', #entity.userId)")
    public void insertInfo(UserAuthenticationInfo entity) {
        sqlSession.insert("userAuthenticationInsert",entity);

    }
}
